package com.wuji1626.spark.rdd.action

import org.apache.spark.{SparkConf, SparkContext}

object RDD_Action_countByKey {

  def main(args: Array[String]): Unit = {

    // Step1: 准备环境
    val sparkConf = new SparkConf().setMaster("local[*]").setAppName("Operator")
    val sc = new SparkContext(sparkConf)
    // Step2: 算子 countByKey
    val rdd = sc.makeRDD(List(("a",1), ("a",2), ("a",3), ("a",4)))
    println(rdd.countByValue())
    val stringToLong: collection.Map[String, Long] = rdd.countByKey()
    println(stringToLong)
    // Step3: 关闭环境
    sc.stop()
  }
}
